package com.coreservlets.jsf.ss12;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;

@ManagedBean
@SessionScoped
public class CityInfoBean
{
	public String cityName = "";
	
	public String getCityName() 
	{
		return cityName;
	}

	public void setCityName(String cityName) 
	{
		this.cityName = cityName;
	}
	
	public List<SelectItem> getCities()
	{
		List<SelectItem> items = new ArrayList<SelectItem>();
		
		items.add( new SelectItem("--- Select a City ---"));
		
		for ( CityInfo cityInfo : CityInfo.cities)
		{
			items.add( new SelectItem( cityInfo.getCityName() ) );
		}
		
		return items;
	}
	
	public String teamNFLName()
	{
		for (CityInfo cityInfo : CityInfo.cities )
		{
			if( cityName.equals( cityInfo.getCityName() ) )
			{
				return( cityInfo.getNlfTeamName() );
			}
		}
		
		return ( "" );
	}
	
	public String teamMLBName()
	{
		for (CityInfo cityInfo : CityInfo.cities )
		{
			if( cityName.equals( cityInfo.getCityName() ) )
			{
				return( cityInfo.getMlbTeamName() );
			}
		}
		
		return ( "" );
	}
}
